package com.mitake.nick.util;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class ReadXmlUtil {

	public static String getUrlData(String userName){
		SAXReader reader = new SAXReader();
		Document doc = null;
		Element element;
		String tempStr = "";
		String[] data;
		
		try {
			doc = reader.read(new URL("http://10.1.99.159:8888/SpWebUserProfile?UserName="+ userName));
		} catch (MalformedURLException | DocumentException e) {
			e.printStackTrace();
		}
        
		Element root = doc.getRootElement();
		while(root.elementIterator("row").hasNext()){
			element = (Element) root.elementIterator("row").next();
			tempStr = element.elementText("profile");
//			System.out.println(tempStr);
			
			try {
				//test write file
				FileUtils.writeStringToFile(new File("C:/SmsTemp/tempFile"), tempStr);
			} catch (IOException e) {
				e.printStackTrace();
			}
			
			data = tempStr.split(",");
			
			for(int i = 0; i < data.length; i++){
				System.out.println(data[i]);
			}
			break;
		}
		
		return tempStr;
	}
}
